package com.taxis.action;

import java.util.List;
import com.taxis.model.Bitacora;
import com.taxis.service.BitacoraDaoService;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BitacoraAction extends ActionSupport {

	private BitacoraDaoService bitacoraService = new BitacoraDaoService();
	private Bitacora bitacora;
	private List<Bitacora> bitacoras;

	public Bitacora getBitacora() {
		return bitacora;
	}

	public void setBitacora(Bitacora bitacora) {
		this.bitacora = bitacora;
	}

	public List<Bitacora> getBitacoras() {
		return bitacoras;
	}

	public String save() throws Exception {
		if (bitacora.getIdBitacora() == null) {
			bitacoraService.insertBitacora(bitacora);
		} else {
			bitacoraService.updateBitacora(bitacora);
		}
		return SUCCESS;
	}

	public String view() throws Exception{
		bitacoras = bitacoraService.getAllBitacoras();
		return SUCCESS;
	}

	public String edit() throws Exception{
		bitacora = bitacoraService.getBitacora(bitacora.getIdBitacora());
		return SUCCESS;
	}

	public String delete() throws Exception {
		bitacoraService.deleteBitacora(bitacora.getIdBitacora());
		return SUCCESS;
	}
}